package com.ds.infrastructure.audit.collector.service;

import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.NotNull;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 作用：
 *
 * @author WeiShaoying
 * @date 2020/8/24
 */
@Slf4j
public class MessageThreadFactory implements ThreadFactory {

    private final AtomicInteger num = new AtomicInteger(0);

    private final String PREFIX = "AuditKafkaMsg-Thread-Pool-Worker-";

    @Override
    public Thread newThread(@NotNull Runnable task) {
        String name = PREFIX + num.incrementAndGet();
        Thread thread = new Thread(null, task, name);
        thread.setDaemon(true);
        log.info("Thread name={}", thread.getName());
        return thread;
    }
}
